package com.hanxu.springboot05mybatis.controller;

import com.hanxu.springboot05mybatis.mapper.StudentMapper;
import com.hanxu.springboot05mybatis.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class StudentController {

    @Autowired
    private StudentMapper studentMapper;


    @RequestMapping("/studentList")
    public List<Student> studentList(){
        List<Student> students = studentMapper.studentList();
        return students;
    }

    @RequestMapping("/studentGetById/{id}")
    public Student studentGetById(@PathVariable("id") int id){
        Student student = studentMapper.studentGetById(id);
        return student;
    }

    @RequestMapping("/addStudent")
    public String addStudent(){
        studentMapper.addStudent(new Student(8, "展示", 1));
        return "addStudent-ok";
    }

    @RequestMapping("/updateStudent/{id}")
    public String updateStudent(@PathVariable("id") int id){
        int i = studentMapper.updateStudent(id);
        return "updateStudent-ok";
    }

    @RequestMapping("/deleteStudent/{id}")
    public  String deleteStudent(@PathVariable("id") int id){
        studentMapper.deleteStudent(id);
        return "deleteStudent-ok";
    }


}
